package com.mdp.workflow.bus.candidate.expression;

import com.mdp.workflow.api.FlowProcinstService;
import org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * 分配给发起人审批的 Expression 流程表达式
 *
 *@author 唛盟开源9哥
 */
@Component
public class TaskAssignStartUserExpression {

    @Resource
    private FlowProcinstService processInstanceService;

    /**
     * 计算审批的候选人
     *
     * @param execution 流程执行实体
     * @return 发起人
     */
    public Set<String> calculateUsers(ExecutionEntityImpl execution) {
        ProcessInstance processInstance = processInstanceService.getProcessInstance(execution.getProcessInstanceId());
        String startUserId = processInstance.getStartUserId();
        return new HashSet<>(Arrays.asList(startUserId));
    }

}
